package org.springframework.core.convert.support;

import org.springframework.core.convert.converter.GenericConverter;

import java.util.Collections;
import java.util.Set;

/**
 * @Name StringToBooleanGenericConverter
 * @Description: String -> Boolean 通用类型转换器 [实现] 类
 * @Version v1.0.0
 * @Author: lichao
 * @Date: 2024-04-11 15:55:45
 **/
public class StringToBooleanGenericConverter implements GenericConverter {
    @Override
    public Set<ConvertiblePair> getConvertibleTypes() {
        return Collections.singleton(new ConvertiblePair(String.class, Boolean.class));
    }

    @Override
    public Object convert(Object source, Class sourceType, Class targetType) {
        return Boolean.valueOf((String) source);
    }
}

